package com.cjyd.hrjb.controller.backend;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cjyd.hrjb.controller.ApiGroup;
import com.cjyd.hrjb.controller.BaseBackendController;
import com.cjyd.hrjb.model.dto.ResponseDto;
import com.cjyd.hrjb.model.vo.UserVo;
import com.cjyd.hrjb.service.UserService;
import org.springframework.web.bind.annotation.*;

/**
 * Created fei wo by 2020/4/7
 */
@RestController
@RequestMapping(ApiGroup.BACKEND_V1)
public class UserManageController extends BaseBackendController {

    private final UserService userService;

    public UserManageController(UserService userService) {
        this.userService = userService;
    }

    @GetMapping("/users")
    public ResponseDto<IPage<UserVo>> list(
            @RequestParam(value = "searchKey", defaultValue = "", required = false) String searchKey,
            @RequestParam(value = "offset", defaultValue = "1", required = false) Integer offset,
            @RequestParam(value = "limit", defaultValue = "15", required = false) Integer limit
    ) {
        return success(userService.listPage(searchKey, offset, limit));
    }

    @GetMapping("/user/sync/{id}")
    public ResponseDto<UserVo> syncXetUser(@PathVariable("id") Long id) {
        return success(userService.syncXetUserInfo(id));
    }

    @GetMapping("/user/recommend/{id}")
    public ResponseDto<UserVo> getRecommendUser(@PathVariable("id") Long id) {
        return success(userService.getRecommendUserInfo(id));
    }

    @GetMapping("/user/subs")
    public ResponseDto<IPage<UserVo>> getSubList(
            @RequestParam("userId") Long userId,
            @RequestParam(value = "offset", defaultValue = "0", required = false) Integer offset,
            @RequestParam(value = "limit", defaultValue = "15", required = false) Integer limit
    ) {
        return success(userService.getSubUserPageList(userId, offset, limit));
    }
}
